﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;
using System.Web;

namespace YouHP.Pages.User.Group
{
    public class InvitePatients :YouHP.Pages.User.Group.GroupBasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

     
        protected List<UserInfo> PatientDataList;
        protected List<DiseaseInfo> DiseaseLst;
        protected List<TreatmentInfo> TreatmentLst;
        protected List<SymptomInfo> SymptomLst;
        protected List<DistrictInfo> ProvinceList;
        protected int PatientCount = 0;
        protected int PatientPageCount = 0;
        protected int PatientPageSize = 15;
        protected int PatientPageIndex = 0;
        protected string PatientPagingString;

        protected void HandleCommon()
        {
            this.SetTitle("圈子邀请");
            this.AddLocation("圈子邀请", "/User/Group/InviteMember.aspx?gid="+GroupData.Id);
            this.AddLocation("邀请站内用户", "/User/Group/InvitePatients.aspx?gid="+GroupData.Id);
            this.AddScriptSrc("/support/Alpha/Js/mootools.js");
            DiseaseLst = DiseaseBLL.Instance.GetAllDiseaseByName("");
            TreatmentLst = TreatmentBLL.Instance.GetAllTreatmentByName("");
            SymptomLst = SymptomBLL.Instance.GetAllSymptomByName("");
            ProvinceList = DistrictBLL.Instance.GetDistrictListByParent(0);
        }

        protected void HandlePost()
        {
        }

        protected void HandleGet()
        {

            PatientSearchCondition cond = new PatientSearchCondition();
            cond.AgeStart = RequestTools.GetQueryInt("agefrom", 0);
            cond.AgeEnd = RequestTools.GetQueryInt("ageto", 0);
            cond.ProvinceId = RequestTools.GetQueryInt("province", 0);
            cond.CityId = RequestTools.GetQueryInt("city", 0);
            cond.TreatmentId = RequestTools.GetQueryInt("trmid", 0);
            cond.TreatmentName = RequestTools.GetQueryString("trmname");
            cond.SymptomId = RequestTools.GetQueryInt("symid", 0);
            cond.SymptomName = RequestTools.GetQueryString("symname");
            cond.DiseaseId = RequestTools.GetQueryInt("dszid", 0);
            cond.DiseaseName = RequestTools.GetQueryString("dszname");
            cond.PatientName = RequestTools.GetQueryString("name");
            cond.Gender = RequestTools.GetQueryString("gender");
            cond.IsAdvanceSearch = RequestTools.GetInt("advance", 0);

            PatientPageIndex = RequestTools.GetQueryInt("page", 1);
            PatientDataList = PatientBLL.Instance.GetPatientList(
                PatientPageSize, PatientPageIndex,
                cond, out PatientCount);

            PatientPageCount = Utils.GetPageCount(PatientCount, PatientPageSize);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            PatientPagingString = this.GetPagingString(PatientPageIndex, PatientPageCount,
                "/User/Group/InvitePatients.aspx" + query, "page");
        }

    }
}